// 1.封装频道获取逻辑
import { useState, useEffect } from "react";
import { getChannelApi } from "@/apis/article";

export default function useChannel ()  {
  // 获取频道列表
  let [channelList, setChannelList] = useState([]);

  useEffect(() => {
    // 封装函数在函数里面使用
    const getchannelList = async () => {
      const res = await getChannelApi();
      setChannelList(res.data.channels);
    };

    // 调用函数
    getchannelList();
    
  }, []);

  // 把组件要用的数据return出去
  return  channelList ;
}